capture log close
log using "log bechtel_mannino_disasterrelief.smcl", replace

version 13      
set more off 



use "1_hist_data.dta", clear
drop if year < 1996 
egen relief_tot = sum(relief_adj)


foreach var of varlist total_damage income pct_poor unemp{
egen `var'p25 = pctile(`var'), p(25)
egen `var'p50 = pctile(`var'), p(50)
egen `var'p75 = pctile(`var'), p(75)
egen `var'p100 = pctile(`var'), p(99.9999)

egen `var'p125 = pctile(`var'), p(12.5)
egen `var'p375 = pctile(`var'), p(37.5)
egen `var'p625 = pctile(`var'), p(62.5)
egen `var'p875 = pctile(`var'), p(87.5)

gen `var'1 = (`var' <= `var'p25) 
gen `var'2 = (`var' > `var'p25 & `var' <= `var'p50) 
gen `var'3 = (`var' > `var'p50 & `var' <= `var'p75) 
gen `var'4 = (`var' > `var'p75) 

gen `var'_f = `var'1
replace `var'_f = 2 if `var'2 == 1
replace `var'_f = 3 if `var'3 == 1
replace `var'_f = 4 if `var'4 == 1
}

gen fatalities = (all_fatalities > 0)
gen injuries = (all_injuries > 0)

* Table 1: Percentiles historical data
sum total_damage, det
sum fatalities, det
sum income, det
sum unemp, det


isid fips year //check for unique identifiers
duplicates report fips year //check for duplicates
duplicates list fips year //lists duplicates

xtset fips year, delta(4)

gen ide_s = (lps_vote == 0)
gen ide_c = (lps_vote == 1)
gen ide_cs = (lps_vote == 2)
gen ide_o = (lps_vote == 3)
gen ide_os = (lps_vote == 4)


*Figure 7: Observed Allocation  
local yeareffect election_2000 election_2004 election_2008
local controls llog_total_damage log_prep llog_prep log_lprep_damage log_population lturnout_pop lcore_state lswing_state
local controls_congress president_yes majority_yes appropsorways_yes

xtreg log_relief i.total_damage_f i.fatalities income4 income3 income2 i.unemp_f i.lps_vote `controls' `controls_congress' `yeareffect', fe vce(cluster fips)
matrix main_emp = (e(b) \ vecdiag(e(V)))'
mat2txt, matrix(main_emp) saving(empirical_results) replace









